#include "camera.h"

camera::camera() {
    camPos.x = 8.00;
    camPos.y = 20.00;
    camPos.z = 8.00;
    camOri.yaw = 0.00;
    camOri.pitch = 0.00;
    camVel.dx = 0.00;
    camVel.dy = 0.00;
    camVel.dz = 0.00;
    sensitivity = 0.05;
}

ori camera::currentOrientation() {
    cout << camOri.yaw << " " << camOri.pitch << endl;
    return camOri;
}

pos camera::currentPosition() {
    cout << camPos.x << " " << camPos.y << " " << camPos.z << endl;
    return camPos;
}

vel camera::currentVelocity() {
    cout << "Velocity: " << camVel.dx << " " << camVel.dy << " " << camVel.dz << endl;
    return camVel;
}

void camera::moveForward() {
    camPos.x += float(sin(camOri.yaw / 180 * 3.141592654f)) * 0.02f;
    camPos.z -= float(cos(camOri.yaw / 180 * 3.141592654f)) * 0.02f;
}

void camera::moveBackward() {
    camPos.x -= float(sin(camOri.yaw / 180 * 3.141592654f)) * 0.02f;
    camPos.z += float(cos(camOri.yaw / 180 * 3.141592654f)) * 0.02f;
}

void camera::strafeLeft() {
    camPos.x -= float(cos(camOri.yaw / 180 * 3.141592654f)) * 0.02f;
    camPos.z -= float(sin(camOri.yaw / 180 * 3.141592654f)) * 0.02f;
}

void camera::strafeRight() {
    camPos.x += float(cos(camOri.yaw / 180 * 3.141592654f)) * 0.02f;
    camPos.z += float(sin(camOri.yaw / 180 * 3.141592654f)) * 0.02f;
}

void camera::moveUp() {
    camPos.y += 0.02f;
}

void camera::moveDown(float y) {
    camPos.y -= y;
}

void camera::rotateLeft(int x) {
    camOri.yaw += x * sensitivity;
    if (camOri.yaw >360)
        camOri.yaw -= 360;
}

void camera::rotateRight(int x) {
    camOri.yaw += x * sensitivity;
    if (camOri.yaw < -360)
        camOri.yaw += 360;
}

void camera::lookUp(int y) {
    camOri.pitch += y * sensitivity;
    if(camOri.pitch > 360)
        camOri.pitch -= 360;
}

void camera::lookDown(int y) {
    camOri.pitch += y * sensitivity;
    if (camOri.pitch < -360)
        camOri.pitch += 360;
}

void camera::updateVel(float dx, float dy, float dz) {
    camVel.dx = dx;
    camVel.dy = dy;
    camVel.dz = dz;
}

void camera::updatePosition() {
    camPos.x += camVel.dx;
    camPos.y += camVel.dy;
    camPos.z += camVel.dz;
}